/**
 * Test algorithms for JettHoughts
 * 
 * Created 12/02/2012
 * 
 * @author Vasili Svirski
 * @version 0.01
 */

package com.jetthoughts.algorithms;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/*
 * Time into time interval
 * 
 */
public class TimeBetween {

	public static boolean isTimeBetween(String time, String start, String end){

		SimpleDateFormat formatter = new SimpleDateFormat ( "hh:mm" ); 

		Date dTime = null;
		Date dStart = null;
		Date dEnd = null;

		try {
			dTime = formatter.parse( time );
			dStart = formatter.parse( start );
			dEnd = formatter.parse( end );
		} catch (ParseException e) {
			e.printStackTrace();
		} 

		// next day situation
		if (dEnd.before(dStart)){
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(dEnd);
			calendar.add(Calendar.DATE, 1);  // number of days to add
			dEnd = calendar.getTime();   
		}

		if (dTime.after(dStart) && dTime.before(dEnd))     
			return true;
		else
			return false;
	}
}
